/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
 */

import { TcbStore } from '../../../../../src/base/internal/pool/store/tcb-store';
import { Work } from '../../../../../src/base/internal/pool/model/work';
import { Priority } from '../../../../../src/base/internal/pool/enum/priority';
import { TCB } from '../../../../../src/base/internal/pool/model/tcb';
import { noop } from '../../../../../src/common/util/noop';
import { ITCB } from '../../../../../src/base/internal/pool/model/itcb';

describe('test tcb store', () => {
  test('test getTCB', () => {
    expect(TcbStore.getTCB('a')).toBeUndefined();
    const work = new Work(Priority.FIRST, undefined, '');
    const tcb: ITCB = new ITCB(work, noop, false, [], () => {
      // empty
    }, '', '', '');
    TcbStore.add(tcb);
    expect(TcbStore.getTCB(tcb.getId())).toBeTruthy();
  });

  test('test clear', () => {
    const work = new Work(Priority.FIRST, undefined, '');
    const tcb: ITCB = new ITCB(work, noop, false, [], () => {
      // empty
    }, '', '', '');
    TcbStore.add(tcb);
    TcbStore.clear();
    expect(TcbStore.getTCB(tcb.getId())).toBeUndefined();
  });

  test('test add', () => {
    const work = new Work(Priority.FIRST, undefined, '');
    const tcb: ITCB = new ITCB(work, noop, false, [], () => {
      // empty
    }, '', '', '');
    TcbStore.add(tcb);
    expect(TcbStore.getTCB(tcb.getId())).toBeDefined();
  });
});
